home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk2.zip / LST13-5.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  867b  |  56 lines

  1. ;
  2. ; *** Listing 13-5 ***
  3. ;
  4. ; Negates several 32-bit values using the branch-on-zero-AX
  5. ; approach.
  6. ;
  7.     jmp    Skip
  8. ;
  9. ; Negates a 32-bit value.
  10. ;
  11. ; Input:
  12. ;    DX:AX = 32-bit value to negate
  13. ;
  14. ; Output:
  15. ;    DX:AX = negated 32-bit value
  16. ;
  17. ; Registers altered: AX, DX
  18. ;
  19. ;-------------------------------------------------------
  20. ; Branching-out exit for Negate32Bits when AX negates to
  21. ; zero, necessitating an increment of DX.
  22. ;
  23. Negate32BitsIncDX:
  24.     inc    dx
  25.     ret
  26. ;
  27. Negate32Bits:
  28.     not    dx
  29.     neg    ax
  30.     jnc    Negate32BitsIncDX
  31.     ret
  32. ;
  33. Skip:
  34.     call    ZTimerOn
  35. ; First, negate zero.
  36.     sub    dx,dx
  37.     mov    ax,dx    ;0
  38.     call    Negate32Bits
  39. ; Next, negate 1 through 50.
  40. X=1
  41.     rept    50
  42.     sub    dx,dx
  43.     mov    ax,X
  44.     call    Negate32Bits
  45. X=X+1
  46.     endm
  47. ; Finally, negate -1 through -50.
  48. X=-1
  49.     rept    50
  50.     mov    dx,0ffffh
  51.     mov    ax,X
  52.     call    Negate32Bits
  53. X=X-1
  54.     endm
  55.     call    ZTimerOff
  56.